package com.example.hasee.zhcd.Adapters;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.hasee.zhcd.Activities.TongJi.CgsDetailActivity;
import com.example.hasee.zhcd.R;
import com.example.hasee.zhcd.Util.GlobalParameter;

import java.util.ArrayList;
import java.util.HashMap;


/**
 * Created by hasee on 2017/9/13.
 */

public class CgscxAdapter extends BaseAdapter {
    private HashMap<String, String> map = (HashMap<String, String>) GlobalParameter.get("loginmap");
    private ArrayList<HashMap<String, String>> list;
    private LayoutInflater itemInflater;
    private Context context;
    private Holder holder;
    private String strCGS;

    public CgscxAdapter(Context context, ArrayList<HashMap<String, String>> list, String strCGS) {
        this.context = context;
        this.list = list;
        this.strCGS = strCGS;
        this.itemInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            holder = new Holder();
            convertView = itemInflater.inflate(R.layout.cgscx_list_item, null);
            holder.fshipname = (TextView) convertView.findViewById(R.id.fshipname);
            holder.fsc = (TextView) convertView.findViewById(R.id.fsc);
            holder.fhl = (TextView) convertView.findViewById(R.id.fhl);
            holder.fdlf = (TextView) convertView.findViewById(R.id.fdlf);
            holder.fzdzz = (TextView) convertView.findViewById(R.id.fzdzz);
            holder.fjd = (TextView) convertView.findViewById(R.id.fjd);
            holder.fzd = (TextView) convertView.findViewById(R.id.fzd);
            holder.fsl = (TextView) convertView.findViewById(R.id.fsl);
            holder.fcszl = (TextView) convertView.findViewById(R.id.fcszl);
            holder.fxx = (TextView) convertView.findViewById(R.id.detail);
            holder.linear = (LinearLayout) convertView.findViewById(R.id.linear);
            holder.line = (View) convertView.findViewById(R.id.line);
            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }
        holder.fshipname.setText((String) list.get(position).get("fshipname"));
        holder.fsc.setText((String) list.get(position).get("fsc"));
        holder.fhl.setText((String) list.get(position).get("fhl"));
        holder.fdlf.setText((String) list.get(position).get("fdlf"));
        holder.fzdzz.setText((String) list.get(position).get("fzdzz"));
        holder.fjd.setText((String) list.get(position).get("fjd"));
        holder.fzd.setText((String) list.get(position).get("fzd"));
//        holder.fsl.setText((String) list.get(position).get("fsl"));
        holder.fcszl.setText((String) list.get(position).get("fcszl"));
        if (list.get(position).get("fxx").length() == 0) {
            holder.fxx.setVisibility(View.INVISIBLE);
            holder.line.setVisibility(View.GONE);
            holder.linear.setVisibility(View.GONE);
        } else {
            holder.fxx.setVisibility(View.VISIBLE);
            holder.line.setVisibility(View.VISIBLE);
            holder.linear.setVisibility(View.VISIBLE);
            holder.fxx.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent = new Intent(context, CgsDetailActivity.class);
                    intent.putExtra("strShip", list.get(position).get("fshipcode"));
                    intent.putExtra("strKSSJ", list.get(position).get("strKSSJ"));
                    intent.putExtra("strJSSJ", list.get(position).get("strJSSJ"));
                    intent.putExtra("strCGS", strCGS);
                    context.startActivity(intent);
                }
            });
        }
        return convertView;
    }

    class Holder {
        private TextView fshipname;
        private TextView fsc;
        private TextView fhl;
        private TextView fdlf;
        private TextView fzdzz;
        private TextView fjd;
        private TextView fzd;
        private TextView fsl;
        private TextView fcszl;
        private TextView fxx;
        private LinearLayout linear;
        private View line;
    }
}
